package com.sbj.service.impl;

import cn.hutool.core.convert.Convert;
import cn.hutool.core.lang.TypeReference;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sbj.dto.req.DivisionReq;
import com.sbj.dto.res.DivisionRes;
import com.sbj.entity.Division;
import com.sbj.mapper.DivisionMapper;
import com.sbj.service.DivisionService;
import com.zmh.framework.constants.Constants;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author summer
 * @version 1.0
 * @date 2024/8/27 15:20
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class DivisionServiceImpl extends ServiceImpl<DivisionMapper, Division> implements DivisionService {

    @Override
    public Page<DivisionRes> lists(DivisionReq divisionReq) {
        Page<Division> page = new Page<>(divisionReq.getPageNum(), divisionReq.getPageSize());
        return Convert.convert(new TypeReference<Page<DivisionRes>>() {},this.page(page));
    }

    @Override
    public Division findOne() {
        return this.list().get(Constants.ZERO);
    }
}
